package com.ok.integral.listener;

import com.ok.integral.domain.dto.OkIntegralDetailDTO;
import com.ok.integral.domain.po.OkIntegralDetail;
import com.ok.integral.service.IOkIntegralDetailService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

/**
 * @ClassName OkIntegralDetailListener
 * @Description 接收积分详细
 * @Author hw
 * @Date 2024/5/12 17:07
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class OkIntegralDetailListener {

    private final IOkIntegralDetailService okIntegralDetailService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "integral_detail_queue",durable = "true"),
            exchange = @Exchange(name = "integral_direct")
    ))
    public void listenerIntegralDetail(OkIntegralDetailDTO okIntegralDetailDTO) {
        log.info("接收积分信息："+okIntegralDetailDTO);
        OkIntegralDetail integralDetail = new OkIntegralDetail();
        BeanUtils.copyProperties(okIntegralDetailDTO,integralDetail);
        okIntegralDetailService.save(integralDetail);
    }
}
